#ifndef S3C2440_GPIO_H_INCLUDED
#define S3C2440_GPIO_H_INCLUDED

#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>

#undef PAGE_SIZE
#undef PAGE_MASK

#define APP_NAME "gpio_ctrl"
#define VERSION "1.0"
#define BUILD_DATE __DATE__

#define PAGE_SHIFT		12
#define PAGE_SIZE  		(1<<PAGE_SHIFT)		/* 4096byte Per Mapped Memory page */
#define PAGE_MASK 		(~(PAGE_SIZE-1) )

#define GPIO_EndAddr	0x560000DC
#define GPIO_StartAddr	0x56000000

#define CLKREG_StartAddr	0x4C000000
#define CLKREG_EndAddr	0x4C000018
#define CLKCON 		0x0C

#define REG(Addr)	(*(volatile unsigned int*) (Addr))

#define ERR_FILEERR -1
#define ERR_FMAPERR -2
#define ERR_GMAPERR -3

#define BLANK_GPA 0x00
#define BLANK_GPB 0x10
#define BLANK_GPC 0x10*2
#define BLANK_GPD 0x10*3
#define BLANK_GPE 0x10*4
#define BLANK_GPF 0x10*5
#define BLANK_GPG 0x10*6
#define BLANK_GPH 0x10*7
#define BLANK_GPJ 0x10*8 + 0x50

#define TYPE_OUT 0x01
#define TYPE_IN 0X00
#define TYPE_SPECIAL 0x02
#define TYPE_RESERVED 0x03

#define STATUS_LOW 0
#define STATUS_HIGH 1

extern int gpio_init(); // 初始化
extern void gpio_exit(); // 销毁
extern void gpio_ioctl(unsigned int blank, int num, int type); // 设置GPIO模式
extern unsigned int gpio_read(unsigned int blank, int num); // 获取GPIO状态
extern void gpio_write(unsigned int blank, int num, int status); //设置GPIO状态

#endif // S3C2440_GPIO_H_INCLUDED
